package com.xubeihong.xubeihong.demo;

import com.xubeihong.xubeihong.TicketTask;
import com.xubeihong.xubeihong.TicketTask2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

@Slf4j
@Component
public class DemoRun2 {

    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(3);
    TicketTask task = new TicketTask();

    //@Scheduled(cron = "59 59 9 * * ?")
    @Scheduled(cron = "59 40 13 * * ?")
    public int getTicket() throws ExecutionException, InterruptedException {
        //System.out.println(new Date()+"执行");
        List<Future> futureList = new ArrayList<>();
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        int i = 3;
        while(i>0){
            i--;
            futureList.add(scheduler.scheduleAtFixedRate(task, 0, 500, TimeUnit.MILLISECONDS));
        }
        //futureList.add(executorService.submit(new TicketTask()));
        //Thread.sleep(2000);
        for(Future future:futureList){
            log.info(future.get()+"");
        }
        return 0;
    }
}
